package com.topnav.mc.exception;

import com.js.lib.result.Result;
import com.topnav.mc.admin.entity.enums.DeviceAlarmCate;

/**
 * 说明：错误信息常量
 * @类名: ExceptionMsgEnum
 *
 * @author   kenny
 * @Date	 2019年12月27日上午11:01:33
 */


public enum ExceptionMsg {

	SUCCESS(0,"操作成功")
	,ERROR(1,"操作失败")
	,EXCEPTION(-1,"Exception：%s")
	/*======================服务错误：101xxx===========================================*/

	/*======================通用错误：102xxx===========================================*/
	,ERROR_COMMON_REQUEST_EXCEPTION(102001, "请求异常：%s")
	//,ERROR_COMMON_PARAM_EXCEPTION(102002, "参数异常：%s")
    //,ERROR_COMMON_BIND_EXCEPTION(102003, "约束异常：%s")
    //,ERROR_COMMON_ENCRYPT_EXCEPTION(102004, "加密异常：%s")
    //,ERROR_COMMON_DATA_EXCEPTION(102005, "数据异常：%s")
    //,ERROR_COMMON_ILLEGAL_REQUEST(102006, "非法请求：%s")
    ,ERROR_COMMON_VALIDATION_EXCEPTION(102007, "参数校验异常：%s")
    //,ERROR_COMMON_REQUEST_BUSY_EXCEPTION(102008, "请求繁忙")
    ,ERROR_DATA_NOT_READABLE_EXCEPTION(102009,"数据不可读: %s")
    /*======================参数错误：103xxx===========================================*/
    //,ERROR_PARAM_VALIDATION_EXCEPTION(103001, "参数校验异常：%s")
    ,ERROR_PARAM_JSON_INCORRECT(103002, "参数JSON格式不正确:%s")
    ,ERROR_PARAM_UNEXPECTED_TYPE(103003,"参数类型异常：%s")
    //,ERROR_PARAM_NOT_EMPTY(103005,"参数<%s>必须提供")
	,ERROR_PARAM_GBSERVER_EXISTS(103006,"GB服务器已存在")
	,ERROR_PARAM_DEVICE_EXISTS(103007,"设备 <%s> 已存在")
	,ERROR_PARAM_CODE_EXISTS(103008,"编码已存在")
	,ERROR_PARAM_NAME_EXISTS(103009,"名称已存在")
	,ERROR_PARAM_DATA_CONFLICTS(103010,"上下级数据有冲突")
	,ERROR_PARAM_ACCOUNT_EXISTS(103011,"登录名已存在")
	,ERROR_PARAM_ROLE_EXISTS(103012,"角色已存在")
	,ERROR_PARAM_COLLECT_SITE_EXISTS(103013,"采集站点已存在")
	,ERROR_PARAM_ORGANIZATION_EXISTS(103020,"机构已存在")

	//Query condition parameters
	/*======================连接第三方平台：104xxx===========================================*/
	,ERROR_LINK_D3PART_EXPIRE(104001,"连接超时,[%s]")
	,ERROR_LINK_D3PART_NONE_ACCOUT(104002,"没集群对讲的登录帐号，可能没权限")
    /*======================数据错误：107xxx===========================================*/
    //,ERROR_DATA_INVALID_FORMAT(107009, "数据格式无效")
    //,ERROR_DEVICE_BLACKLIST(111002, "【%s】访问过于频繁,已被关入小黑屋,%s秒钟后解除")

	/* ======================数据删除提示：105xxx===========================================*/
	,ERROR_DELETE_USER_USED_BY_DOCUMENT(105005,"此用户已有视频文件记录，不能删除")
	,ERROR_DELETE_USER_USED_BY_ORGANIZATION(105008,"此用户已分配部门权限，请先解除部门权限，再删除")
	,ERROR_DELETE_USER_USED_BY_ROLE(105011,"此用户已分配角色权限，请先解除角色绑定，再删除")
	,ERROR_DELETE_USER_USED_DEVICEALARM(105014,"此用户已在设备报警处置中被使用，不能删除")
	,ERROR_DELETE_USER_USED_FAVOREITE(105017,"此用户已有收藏设备，请先取消收藏，再删除")
	,ERROR_DELETE_SITE_USED_BY_DOCUMENT(105020,"此站点已有视频文件记录，不能删除")
	,ERROR_DELETE_ROLE_USED_BY_PERMISSION(105022,"此角色已有分配权限，请解除分配的权限，再删除")
	,ERROR_DELETE_ROLE_USED_BY_ORGANIZATION(105024,"此角色已分配用户部门权限，请先解除用户部门权限，再删除")
	,ERROR_DELETE_ROLE_USED_BY_USER(105026,"此角色已分配给用户权限，请先解除用户角色绑定，再删除")
	,ERROR_DELETE_PERMISSION_USED_BY_ROLE(105028,"此权限已分配给角色，请先解除角色权限绑定，再删除")
	,ERROR_DELETE_GBSERVER_USED_BY_DEVICE(105030,"此国标服务已被设备使用，请先解除设备国标服务器绑定，再删除")
	,ERROR_DELETE_OGRANIZATION_USED_BY_ORGANIZATION(105032,"此机构已包含下级，不能删除")
	,ERROR_DELETE_OGRANIZATION_USED_BY_USER(105034,"此机构已被注册的用户使用，不能删除")
	,ERROR_DELETE_OGRANIZATION_USED_BY_DEVICE(105036,"此机构已被注册的设备使用，不能删除")
	,ERROR_DELETE_OGRANIZATION_USED_BY_DOCUMENT(105038,"此机构已存在视频文件，不能删除")
	,ERROR_DELETE_OGRANIZATION_USED_BY_SITE(105040,"此机构已被注册的采集站使用，不能删除")
	,ERROR_DELETE_OGRANIZATION_USED_BY_FENCE(105042,"此机构已被围栏使用，不能删除")
	,ERROR_DELETE_DEVICE_USED_BY_CHANNEL(105044,"此设备有通道记录，不能删除")
	,ERROR_DELETE_DEVICE_USED_BY_LOG(105048,"此设备存在日志记录，不能删除")
	,ERROR_DELETE_DEVICE_USED_BY_DCOUMENT(105050,"此设备已有视频文件在用, 不能删除")
	,ERROR_DELETE_DEVICE_USED_BY_SOSALARM(105052,"此设备已有SOS报警数据, 不能删除")
	,ERROR_DELETE_DEVICE_USED_BY_FENCEALARM(105058,"此设备已有围栏报警数据, 不能删除")
	,ERROR_DELETE_DEVICE_USED_BY_FAVOREITE(105060,"此设备已被收藏, 不能删除")
	,ERROR_DELETE_FENCE_USED_BY_FENCEALARM(105062,"此围栏已有报警数据, 不能删除")
	,ERROR_DELETE_FENCE_USED_BY_PLOYGON(105064,"此围栏已有地图数据, 不能删除")
	,ERROR_DELETE_AUTORIZATION_USED_BY_PARENT(105068,"此菜单存在下级, 不能删除")
	,ERROR_DELETE_AUTORIZATION_USED_BY_ROLE(105082,"此菜单已被设置权限, 不能删除")
	,ERROR_DISABLED_ALARM_NOTIFY_FAILED(105084, "禁止报警通知失败")
	,ERROR_DELETE_FILE_ONLAY_ADMIN_FAILED(105088, "只有系统管理员才能删除文件")
	,ERROR_DELETE_USER_USED_BY_LOG(105090,"此用户存在日志记录，不能删除")
	,ERROR_DELETE_USER_USED_BY_SELF(105091,"此用户正在登录，不能删除")


	/*======================结果错误：118xxx===========================================*/
    ,ERROR_NOT_EXISTS_EXCEPTION(118001, "不存在的设备编号")
	,ERROR_NOT_EXISTS_SITE_EXCEPTION(118002, "设备 [%s] 未注册")
    ,ERROR_DEVICE_REGISTER_EXCEPTION(118006, "数据登记错误：%s")
	,ERROR_NOT_DATA_EXCEPTION(118008, "没有数据返回")
	,ERROR_NOT_BIND_SERVER_EXISTS(118010,"没有设置 国标服务器")
	,ERROR_NOT_ONLINE_SERVER_EXISTS(118012,"没有在线的国标服务器")
	,ERROR_SEND_CAMMAND_TO_DEVICE_FAILED(118014,"给设备发送升级指令失败")
	,ERROR_SERVER_TIMEOUT_NOT_RESPONED(118016,"服务端超时未响应")
	,ERROR_SERVER_UNABLED_TO_CONNECT_NS_SERVER(118020,"无法连接国标服务器")
	,ERROR_OPERATION_HAS_BEEN_CANCELS_BY_USER(118022,"操作已被用户取消")
	,ERROR_NOT_NS_SERVER_EXISTS_EXCEPTION(118024, "不存在的国标服务器")
	,ERROR_REAL_TIME_ATREAM_ON_DEMAND_FAILURE(118026, "实时流点播失败")
	,ERROR_GET_PARAM_FROM_NS_SErVER_FAILURE(118028, "取国标服务器的参数失败")


    /*======================对方HTTP接口异常：119xxx===========================================*/
    //,ERROR_ACCESS_HTTP_API(119001, "目标系统HTTP接口异常,【%s】")

	/*======================认证错误：120xxx===========================================*/
	,ERROR_AUTHENTICATION_NOT_EXISTS_USER(120001, "不存在的用户,[%s]")
	,ERROR_AUTHENTICATION_FAILE(120002, "认证失败，请重新登录")
	,ERROR_AUTHENTICATION_ACCESS_DENIED(120003, "权限不足")
	,ERROR_AUTHENTICATION_LOGIN_FAILE(120004, "登录失败，用户名或密码错误")
	,ERROR_AUTHENTICATION_ORIGIN_PASSWORD_LOSE(121005, "原密码必须提供！")
	,ERROR_AUTHENTICATION_NEW_PASSWORD_LOSE(121006, "新密码必须提供！")
	,ERROR_AUTHENTICATION_ORIGIN_PASSWORD_DIFF(121007, "旧密码不一致！")
	,ERROR_AUTHENTICATION_PASSWORD_FAILE(120008, "密码错误")
	,ERROR_AUTHENTICATION_ENABLED_FAILE(120009, "用户 [%s] 已被禁止登录！")
	,ERROR_AUTHENTICATION_CONFIRM_PASSWORD_LOSE(121010, "确认密码必须提供！")
	,ERROR_AUTHENTICATION_NEW_CONFIRM_PASSWORD_DIFF(121011, "新密码和确认密码不一致！")
	,ERROR_AUTHENTICATION_EFFE(120012, "登录信息已失效，请重新登录")
	,ERROR_AUTHENTICATION_EMPTY_ACCOUNT(120017, "账号不能为空")
	,ERROR_AUTHENTICATION_EMPTY_PASSWORD(120018, "密码不能为空")
	,ERROR_AUTHENTICATION_RESET_PASSWORD_NOADMIN(120019, "只有系统管理员才能重置密码")
	,ERROR_AUTHENTICATION_RESET_PASSWORD_FAILED(120020, "重置密码失败")
	,ERROR_AUTHENTICATION_CHANGE_PASSWORD_FAILED(120021, "修改密码失败")
	,ERROR_PARAM_TOKEN_NOT_PROVIDED(120025,"TOKEN 参数必须提供")
	,ERROR_PARAM_CONDITION_NOT_PROVIDED(120028,"查询条件参数必须提供")
	,ERROR_AUTHENTICATION_VERIFY_EMPTY(120030, "验证码不能为空")
	,ERROR_AUTHENTICATION_SESSIONID_EMPTY(120032, "SessionId 不能为空")
	,ERROR_AUTHENTICATION_VERIFYCODE_EXPIRE(120034, "验证码已期")
	,ERROR_AUTHENTICATION_VERIFYCODE_FAILED(120036, "验证码验证失败")
	,ERROR_PARAM_START_TIME_AND_END_TIME_NOT_PROVIDED(120038,"参数开始时间和结束时间必须提供")
	,ERROR_PARAM_TIME_AND_DEVICE_NOT_PROVIDED(120040,"参数时间和设备必须提供")
	,ERROR_PARAM_TIME_NOT_PROVIDED(120042,"参数时间必须提供")
	,ERROR_PARAM_DEVICE_NOT_PROVIDED(120044,"参数设备必须提供")
	,ERROR_PARAM_INCOMPLETE(120046,"参数不完整")
	,ERROR_AUTHENTICATION_GET_VERIFYCODE_FAILED(120048, "取得验证码错误")



	//WVP ERROR
	/* ======================数据删除提示：125100- wvp.code ===========================================*/
	/* ======================小于 0 ===========================================*/
	,FAIL(125000, "失败"), //125100-100
	ERROR_WVP_FOR_SIGNALLING_TIMEOUT(125099, "信令超时"), //125000-1
	ERROR_WVP_FOR_STREAM_TIMEOUT(125098, "收流超时"), //125000-2
	ERROR_WVP_FOR_RESOURCE_EXHAUSTION(125097, "资源耗尽"),//125000-3
	ERROR_WVP_FOR_CATCH_DATA(125096, "缓存数据异常"),//125000-4
	ERROR_WVP_FOR_SIGNALLING_ERROR(125095, "收到信令错误"),//125000-5
	ERROR_WVP_FOR_STREAM_PARSING_EXCEPTIONS(125094, "流地址解析错误"),//125000-6
	ERROR_WVP_FOR_SDP_PARSING_EXCEPTIONS(125093, "SDP信息解析失败"),//125000-7
	ERROR_WVP_FOR_SSRC_UNAVAILABLE(125092, "SSRC不可用"), //125000-8
	ERROR_WVP_FOR_RESET_SSRC(125091, "重新设置收流信息失败"), //125000-9
	ERROR_WVP_FOR_SIP_SENDING_FAILED(125090, "命令发送失败"), //125000-10
	ERROR_WVP_FOR_ASSIST_NOT_READY(125089, "没有可用的assist服务"),//125000-11
	ERROR_WVP_FOR_PARAMETER_ERROR(125087, "参数异常") //125000-13

	/* ======================大于0且大于100  ===========================================*/
	/* ======================125100 + wvp.code  ===========================================*/
	,ERROR_WVP_ERROR400(125500, "参数或方法错误")//400
	,ERROR_WVP_ERROR404(125504, "资源未找到")//404
	,ERROR_WVP_ERROR403(125503, "无权限操作")//403
	,ERROR_WVP_ERROR401(125501, "请登录后重新请求")//401
	,ERROR_WVP_ERROR500(125600, "系统异常")//500

	/* ======================wvpcode=100 125200开始 ===========================================*/
	,ERROR_WVP_ERROR200(125200, "失败")
	,ERROR_WVP_ERROR201(125201, "点播超时")
	,ERROR_WVP_ERROR202(125202, "未找到可用的zlm")
	,ERROR_WVP_ERROR203(125203, "单端口收流时不支持TCP主动方式收流")
	,ERROR_WVP_ERROR204(125204, "点播失败， redis缓存streamId等于null")
	,ERROR_WVP_ERROR205(125205, "点播未找到")
	,ERROR_WVP_ERROR206(125206, "未找到视频流信息, 视频流可能已经停止")
	,ERROR_WVP_ERROR207(125207, "转码失败")
	,ERROR_WVP_ERROR208(125208, "使用的流媒体已经停止运行")
	,ERROR_WVP_ERROR209(125209, "命令发送失败")
	,ERROR_WVP_ERROR210(125210, "语音广播操作超时, 设备未返回应答指令")
	,ERROR_WVP_ERROR211(125211, "设备超时无回应")
	,ERROR_WVP_ERROR212(125212, "不存在要关闭的语音流")
	,ERROR_WVP_ERROR213(125213, "设备不存在")
	,ERROR_WVP_ERROR214(125214, "命令发送失败")
	,ERROR_WVP_ERROR215(125215, "流媒体不存在")
	,ERROR_WVP_ERROR216(125216, "不存在的设备")
	,ERROR_WVP_ERROR217(125217, "设备正在使用")
	,ERROR_WVP_ERROR218(125218, "设备正在对讲中")
	,ERROR_WVP_ERROR219(125219, "语音广播操作失败")
	;
	/**
	 * code=100
	 * msg=
	 * 点播超时
	 * 未找到可用的zlm
	 * 单端口收流时不支持TCP主动方式收流
	 * 点播失败， redis缓存streamId等于null
	 * 点播未找到
	 * 设备[" + deviceId + "]不存在
	 * 命令发送失败: " + e.getMessage()
	 * 未找到视频流信息, 视频流可能已经停止
	 * 未找到视频流信息, 视频流可能已停止推流
	 * 转码失败
	 * 流媒体：" + mediaServerId + "不存在"
	 * 使用的流媒体已经停止运行
	 * 不存在的设备ID: %s",deviceId
	 * 设备正在使用：%s",deviceId)
	 * 设备正在对讲中：%s",deviceId)
	 * 语音广播操作失败，错误码：
	 * 命令发送失败
	 * 语音广播操作超时, 设备未返回应答指令
	 * 设备超时无回应
	 * 不存在要关闭的语音流
	 *
	 *
	 *     SUCCESS(0, "成功"),
	 *     ERROR100(100, "失败"),
	 *     ERROR400(400, "参数或方法错误"),
	 *     ERROR404(404, "资源未找到"),
	 *     ERROR403(403, "无权限操作"),
	 *     ERROR401(401, "请登录后重新请求"),
	 *     ERROR500(500, "系统异常");
	 *
	 *
	 *
	 */

	public Integer code;
	public String desc;

	private ExceptionMsg(Integer code, String desc) {
		this.code = code;
		this.desc = desc;
	}

	public Integer getCode() {return code;}

	public void setCode(Integer code) {this.code = code;	}

	public String getDesc() {return desc;}

	public void setDesc(String desc) {this.desc = desc;}


	/**
	 * 从WVP返回的错误代码
	 * 有<0,
	 * =100 自定错误
	 * >400
	 * @param wvpCode
	 * @return
	 */
	public static ExceptionMsg getWvpException(int wvpCode){
		for (ExceptionMsg entity : ExceptionMsg.values()) {
			if (entity.getCode().equals(125100-wvpCode)) {
				return entity;
			}
		}
		return ERROR;
	}

	public static ExceptionMsg getWvpException(int wvpCode,String wvpMsg){
		if (wvpCode < 0){
			return getWvpException(wvpCode);
		}
		if (wvpCode == 100){
			for (WvpException entity : WvpException.values()) {
				if (wvpMsg.startsWith(entity.getLike())){
					for (ExceptionMsg entity1 : ExceptionMsg.values()){
						if (entity1.getCode().equals(entity.getCode())){
							return entity1;
						}
					}
				}
			}
		}
		if (wvpCode >= 400 && wvpCode <= 400){
			for (ExceptionMsg entity : ExceptionMsg.values()) {
				if (entity.getCode().equals(125100+wvpCode)) {
					return entity;
				}
			}
		}
		return ERROR;
	}

	/**
	 *填充描述
	 * @param args 填充内容
	 * @return
	 */
	public String getFillDesc(Object ... args){
		if (args != null)
			return String.format(this.desc, args);
		else
			return this.desc;
	}

}
